<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.*"%>
<%@ page import="com.fc.util.*" %>
<%@ page import="com.fc.model.Item" %>
<%@ page import = "com.fc.control.DateControl"%>
<%@ page import="com.fc.control.ItemControl" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>item</title>
		<script type="text/javascript" src="../../../js/jquery.js"></script>
		<link href="../../../css/info_teacher.css" rel="stylesheet" type="text/css" />
		<script type="text/javascript">
	$(document).ready(function() {
		$('#formdiv').hide();
		$('[name=form_upload]').hide();
		$('#update_item').hide();
		$('#upload_btn').click(function() {
		$('[name=form_upload]').slideToggle();
				});
		$('#add_item').click(function() {
			$('#formdiv').slideToggle();
		});
		$('[name=edit]').click(function() {
		    $('#update_itemId').val($(this).prev().val());
		    $('#update_total_use').val($(this).parent().prev().prev().text());
			$('#update_item_name').val($(this).parent().prev().text());
			$('#update_item').fadeIn();
		});
		$('#cancel').click(function() {
			$('#update_item').fadeOut();
		})
			$('#submit_btn').click(function() {
			$.ajax( {
				type : "get",
				cache : false,
				url : "item_add.jsp",
				dataType : "json",
				data : {
					store_id : $('#new_store_id').val(),
					total_use : $('#new_total_use').val(),
					item_name : $('#new_item_name').val(),
				},
				success : function(data) {
					if (data.status == 1) {
						window.location.reload();
					} else {
						alert("插入失败！");
					}
				}
			});
		})
		$('#update_btn').click(function() {
			$.ajax( {
				type : "get",
				cache : false,
				url : "item_update.jsp",
				dataType : "json",
				data : {
					total_use : $('#update_total_use').val(),
					item_name : $('#update_item_name').val(),
					itemId : $('#update_itemId').val()
				},
				success : function(data) {
					if (data.status == 1) {
						window.location.reload();
					} else {
						alert("修改失败！");
					}
				}
			});
		})
				$('[name=delete]').click(function() {
					var isConfirm = confirm("确认删除？");
					if (isConfirm == true) {
						$.ajax( {
							type : "get",
							cache : false,
							url : "item_delete_do.jsp",
							dataType : "json",
							data : {
								itemId : $(this).prev().prev().val()
							},
							success : function(data) {
								if (data.status == 1) {
									window.location.reload();
								} else {
									alert("删除失败！");
						}
					}
				});
			}
		})
	
	})
</script>
</head>
<body>
<div class="main">
<form>
<strong>项目列表</strong>
   <table>
   <thead>
   <tr>
   	<th width="100">编号</th>
   	<th width="150">店铺编号</th>
   	<th width="150">使用次数</th>
   	<th width="200">项目名称</th> 	
   	<th width="150">操作</th>  
   </tr>
</thead>
<tbody>
<%
	request.setCharacterEncoding("UTF-8");
	
	int pages = ParamUtil.getInt(request, "pages", 0);
	int id=ParamUtil.getInt(request,"id",0);
	int rowsPerPage = ParamUtil.getInt(request, "pageSize", 10);
	ItemControl ic = new ItemControl();
	Item item = new Item();


	List<Item> list = new ArrayList<Item>();
	list = (List) ic.getItem(pages,rowsPerPage); 
	      
	for (int i = 0; i < list.size(); i++) {
		item = list.get(i);
%>  
	
		<tr>
	    <td align="center"><%=item.getId()%></td>
		<td align="center"><%=item.getStore_id()%></td>
		<td align="center"><%=item.getTotal_use()%></td>
		<td align="center"><%=item.getItem_name()%></td>
		<td align="center">
			<input type="hidden" value="<%=item.getId()%>">
			<input type="button" value="编辑" name="edit">
			<input type="button" value="删除" name="delete">
		</td>
		</tr>
	<%
		}
	%>   	
   	</tbody>
   </table>
   <center><input type="button" id="add_item" value="添加教师" /></center>
	</form>
		<div id="formdiv">
			<form action="#" method="post">
				<table width="100%" border="0" cellspacing="0" cellpadding="0">
					<tr>
						<td>
							店铺编号：
							<input type="text" id="new_store_id" name="new_store_id" value="" />
						</td>
						<td>
							项目名称：
							<input type="text" id="new_item_name" name="item_name" value="" />
						</td>
				        <td>
							<input type="button" id="submit_btn" value="提交" />
						</td>		
						</tr>
				</table>
			</form>
		</div>
			
			<div id="update_item">
				使用次数：
				<input type="text" id="update_total_use" />
				项目名称：
				<input type="text" id="update_item_name" />
				<input type="hidden" id="update_itemId" />
				<input type="button" id="update_btn" value="修改">　
				<input type="button" id="cancel" value="取消">
			</div>
		</div>
</body>
</html>